// DlgColor.cpp : implementation file
//

#include "stdafx.h"
#include "PhotoEdit.h"
#include "DlgColor.h"
#include "afxdialogex.h"


// CDlgColor dialog

IMPLEMENT_DYNAMIC(CDlgColor, CDialogEx)

CDlgColor::CDlgColor(CWnd* pParent /*=NULL*/)
	: CDialogEx(CDlgColor::IDD, pParent)
{

}
CDlgColor::CDlgColor(CDlgHomeTab* pParent)
	: CDialogEx(CDlgColor::IDD, pParent)
{
	m_pHomeTab = pParent;
	//m_pHomeTab->m_pPhoto->CreateBackup();
	
}
CDlgColor::~CDlgColor()
{
}

void CDlgColor::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_SLIDER_BRIGHTNESS, m_ctrBrightness);
	DDX_Control(pDX, IDC_SLIDER_CONTRAST, m_ctrContrast);
}

BOOL CDlgColor::OnInitDialog()
{
	CDialogEx::OnInitDialog();
	m_pHomeTab->m_pPhoto->CreateBackup();

	m_pHomeTab->m_pPhoto->BeginComplex();
	m_ctrBrightness.SetRange(0,200);
	m_ctrBrightness.SetPos(100);
	m_ctrContrast.SetRange(0,200);
	m_ctrContrast.SetPos(100);

	return TRUE; 
}


BEGIN_MESSAGE_MAP(CDlgColor, CDialogEx)
	ON_WM_HSCROLL()
	ON_BN_CLICKED(IDCANCEL, &CDlgColor::OnBnClickedCancel)
//	ON_WM_CLOSE()
ON_BN_CLICKED(IDOK, &CDlgColor::OnBnClickedOk)
END_MESSAGE_MAP()


// CDlgColor message handlers


void CDlgColor::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
	// TODO: Add your message handler code here and/or call default
	
	m_pHomeTab->m_pPhoto->RetoreBackup(false);
	
	int b = m_ctrBrightness.GetPos()-100;
	float c = 1+(float)(m_ctrContrast.GetPos()-100)/150;
	
	m_pHomeTab->m_pPhoto->AdjustContrast(c,b);
	m_pHomeTab->RefreshDraw();
	CDialogEx::OnHScroll(nSBCode, nPos, pScrollBar);
}


void CDlgColor::OnBnClickedCancel()
{
	// TODO: Add your control notification handler code here
	m_pHomeTab->m_pPhoto->EndComplex();
	m_pHomeTab->m_pPhoto->RetoreBackup(true);
	
	m_pHomeTab->RefreshDraw();
	CDialogEx::OnCancel();
}



void CDlgColor::OnBnClickedOk()
{
	// TODO: Add your control notification handler code here
	m_pHomeTab->m_pPhoto->EndComplex();
	CDialogEx::OnOK();
}
